<div id="friendLinks-root"></div>
<div class="panel panel-default">
    <div class="panel-heading">
        友情链接列表
        <div class="btn-group btn-group-sm">
            <button id="add" class="btn btn-primary">添加</button>
            <button id="refresh" class="btn btn-info">刷新</button>
        </div>
    </div>
    <table class="table table-hover">
        <thead>
        <tr>
            <td>ID</td>
            <td>名称</td>
            <td>地址</td>
            <td>图标</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {% for l in links %}
        <tr>
            <td>{{l.id}}</td>
            <td>{{l.name}}</td>
            <td><a href="http://{{l.domain}}" target="_blank">{{l.domain}}</a></td>
            <td>{% raw ("<img src='%s'>" % l.logo) if l.logo else "" %}</td>
            <td>
                <div class="btn-group btn-group-sm">
                    <button id="/personal/site/friendLink-{{l.id}}-EDIT" class="btn btn-success">
                        编辑
                    </button>
                    <button id="/personal/site/friendLink-{{l.id}}-DELETE" class="btn btn-danger">
                        删除
                    </button>
                </div>
            </td>
        </tr>
        {% end %}
        </tbody>
    </table>
</div>
<script type="text/javascript">

    $(document).ready(function () {
        $("button#add").click(function(){
            new Ajax("friendLinks-root", "/personal/site/friendLink", "PUT");
        });
        $("button#refresh").click(function () {
            new Ajax("tab-item-friendLink", "/personal/site/friendLink");
        });
        $("button[id^='/personal/site/friendLink-']").click(function () {
            var ss = $(this).attr("id").split('-');
            if(ss[2] == "EDIT"){
                new Ajax("friendLinks-root", "/personal/site/friendLink", "PUT", {id:ss[1]});
            }
            else if(ss[2] == "DELETE"){
                if (confirm("你确定要进行此操作么？")) {
                    new Ajax("friendLinks-root", ss[0]+"/"+ss[1], "DELETE");
                }
            }

        });
    });
</script>
<p>&nbsp;</p>